public class Test {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t1 = new Thread(()->{
            synchronized(A) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (B) {
                    System.out.println("线程 t1 拿到B锁");
                }
            }
        });

        Thread t2 = new Thread(()->{
            synchronized(B) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (A) {
                    System.out.println("线程 t2 拿到A锁");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
